package src.cn.hquanheng.week3;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

import org.junit.Test;

public class TestforEach {
	@Test
	public void testList() {
		List<String> list = new ArrayList<String>();
		list.add("abc");
		list.add("def");
		list.add("ghi");
		list.add("jklm");
		list.add("nopqr");
		
		list.forEach(element->{
			if(element.length()>3) {
				System.out.println(element);
			}
		});
		
		list.forEach(new Consumer<String>() {

			@Override
			public void accept(String t) {
				if(t.length()>3) {
					System.out.println(t);
				}
			}
		});
	}
	@Test
	public void testMap() {
		Map<String, Integer> map = new HashMap<String,Integer>();
		map.put("zs",66);
		map.put("ls",76);
		map.put("ww",68);
		map.put("zl",96);
		map.put("ql",56);
		
		map.forEach((k,v)->{
			if(v<60) {
				System.out.println(k+":"+v);
			}
		});
		
		map.forEach(new BiConsumer<String, Integer>() {

			@Override
			public void accept(String t, Integer u) {
				if(u<60) {
					System.out.println(t+":"+u);
				}
			}
		});
	}
	
}
